home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Screenblankers / Blanker / Source / winhand.c < prev   
Encoding:
C/C++ Source or Header  |  1996-09-27  |  7.4 KB  |  285 lines

  1. /*
  2.  *    Copyright (c) 1993 Michael D. Bayne.
  3.  *    All rights reserved.
  4.  *
  5.  *    Please see the documentation accompanying the distribution for distribution and disclaimer information.
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <exec/memory.h>
  10.  
  11. #include <intuition/intuition.h>
  12. #include <intuition/gadgetclass.h>
  13. #include <workbench/workbench.h>
  14.  
  15. #include <libraries/gadtools.h>
  16. #include <libraries/reqtools.h>
  17.  
  18. #include <graphics/displayinfo.h>
  19.  
  20. #include <clib/exec_protos.h>
  21. #include <clib/dos_protos.h>
  22. #include <clib/intuition_protos.h>
  23. #include <clib/icon_protos.h>
  24. #include <clib/gadtools_protos.h>
  25. #include <clib/graphics_protos.h>
  26. #include <clib/reqtools_protos.h>
  27. #include <clib/alib_protos.h>
  28.  
  29. #include "defs.h"
  30. #include "Blanker.h"
  31. #include "Blanker_rev.h"
  32.  
  33. #include "protos/main.h"
  34. #include "protos/cxhand.h"
  35. #include "protos/messaging.h"
  36. #include "protos/prefs.h"
  37.  
  38. UBYTE    prefName[108] = "", prefDir[108] = "SYS:Prefs/Presets/Blanker", modInfo[64];
  39.  
  40. ULONG doImage( UBYTE *path )
  41. {
  42.     struct DiskObject *bDO;
  43.     struct Image *Image;
  44.  
  45.     ULONG x = ( FontX * 6 + 4 ) / 8 + 3, y = ( FontY * 38 + 4 ) / 8 + 2;
  46.     ULONG dx = ( FontX * 85 + 4 ) / 8 - 6, dy = ( FontY * 25 + 4 ) / 8 - 4;
  47.  
  48.     if(!( bDO = GetDiskObjectNew( path ))) {
  49.         EZRQ( "GetDiskObjectNew() failed. Can't load image." );
  50.         return( 1L );
  51.     }
  52.     
  53.     Image = ( struct Image * )( bDO->do_Gadget.GadgetRender );
  54.     Image->LeftEdge = x + OffX + (dx-Image->Width)/2;
  55.     Image->TopEdge = y + OffY + (dy-Image->Height)/2;
  56.     EraseRect( BlankerWnd->RPort, x + OffX, y + OffY, x + dx + OffX, y + dy + OffY );
  57.     DrawImage( BlankerWnd->RPort, Image, 0, 0 );
  58.     FreeDiskObject( bDO );
  59.  
  60.     return( 0L );
  61. }
  62.  
  63. void setPrefs( struct BlankerPrefs *cP, UBYTE gad )
  64. {
  65.     struct NameInfo sInf;
  66.     struct Menu *MenuStrip;
  67.     struct MenuItem *Item;
  68.  
  69.     if(( gad == GD_TOUT )||( gad == Blanker_CNT )) GT_SetGadgetAttrs( BlankerGadgets[GD_TOUT], BlankerWnd, 0L,
  70.         GTIN_Number, (cP->bp_Timeout)/10, 0L );
  71.  
  72.     if(( gad == GD_PKEY )||( gad == Blanker_CNT )) GT_SetGadgetAttrs( BlankerGadgets[GD_PKEY], BlankerWnd, 0L,
  73.         GTST_String, cP->bp_PopKey, 0L );
  74.  
  75.     if(( gad == GD_BKEY )||( gad == Blanker_CNT )) GT_SetGadgetAttrs( BlankerGadgets[GD_BKEY], BlankerWnd, 0L,
  76.         GTST_String, cP->bp_BlankKey, 0L );
  77.  
  78.     if(( gad == GD_MODINFO )||( gad == Blanker_CNT )) {
  79.         GT_SetGadgetAttrs( BlankerGadgets[GD_BMOD], BlankerWnd, 0L, GA_Disabled, BS_NOPRFS & cP->bp_Flags,
  80.             0L );
  81.         GT_SetGadgetAttrs( BlankerGadgets[GD_MODINFO], BlankerWnd, 0L, GTTX_Text, modInfo, 0L );
  82.         if( BS_VALMOD & cP->bp_Flags ) doImage( doPath( cP->bp_Name, cP->bp_Dir ));
  83.         else doImage( "PROGDIR:Blanker" );
  84.     }
  85.  
  86.     if(( gad == GD_MDISPLAY )||( gad == Blanker_CNT )) {
  87.         if( GetDisplayInfoData( 0l, ( UBYTE * )&sInf, sizeof( struct NameInfo ), DTAG_NAME, cP->bp_Mode ))
  88.             GT_SetGadgetAttrs( BlankerGadgets[GD_MDISPLAY], BlankerWnd, 0L, GTTX_Text, sInf.Name, 0L );
  89.         else GT_SetGadgetAttrs( BlankerGadgets[GD_MDISPLAY], BlankerWnd, 0L, GTTX_Text, "No Monitor Info", 0L );
  90.         GT_SetGadgetAttrs( BlankerGadgets[GD_SDEP], BlankerWnd, 0L, GTNM_Number, 1<<(cP->bp_Depth), 0L );
  91.         GT_SetGadgetAttrs( BlankerGadgets[GD_SMODE], BlankerWnd, 0L, GA_Disabled,
  92.             !( cP->bp_Flags & BS_ASKSCR ), 0L );
  93.     }
  94.  
  95.     if( gad == Blanker_CNT ) {
  96.         MenuStrip = BlankerWnd->MenuStrip;
  97.         ClearMenuStrip( BlankerWnd );
  98.  
  99.         Item = MenuStrip->NextMenu->NextMenu->FirstItem;
  100.         if( bPrefs->bp_Flags & BS_RANDOM ) Item->Flags |= CHECKED;
  101.         else Item->Flags &= ~CHECKED;
  102.  
  103.         ResetMenuStrip( BlankerWnd, MenuStrip );
  104.     }
  105. }
  106.  
  107. int TOUTClicked( void )
  108. {
  109.     bPrefs->bp_Timeout = 10*(((struct StringInfo*)(BlankerGadgets[GD_TOUT])->SpecialInfo)->LongInt);
  110.     return( UpdateCX() );
  111. }
  112.  
  113. int BKEYClicked( void )
  114. {
  115.     CopyMem( ((struct StringInfo *)(BlankerGadgets[GD_BKEY])->SpecialInfo )->Buffer, bPrefs->bp_BlankKey, 256 );
  116.     return( UpdateCX() );
  117. }
  118.  
  119. int PKEYClicked( void )
  120. {
  121.     CopyMem( ((struct StringInfo *)(BlankerGadgets[GD_PKEY])->SpecialInfo )->Buffer, bPrefs->bp_PopKey, 256 );
  122.     return( UpdateCX() );
  123. }
  124.  
  125. int HIDEClicked( void )
  126. {
  127.     return( CLOSEWIN );
  128. }
  129.  
  130. int SAVEClicked( void )
  131. {
  132.     saveDefaultPrefs( bPrefs );
  133.  
  134.     return( OK );
  135. }
  136.  
  137. int QUITClicked( void )
  138. {
  139.     return( QUIT );
  140. }
  141.  
  142. int SMODEClicked( void )
  143. {
  144.     struct rtScreenModeRequester *smRequest;
  145.  
  146.     if( smRequest = rtAllocRequestA( RT_SCREENMODEREQ, 0l )) {
  147.         rtChangeReqAttr( smRequest, RTSC_DisplayID, bPrefs->bp_Mode, RTSC_DisplayDepth, bPrefs->bp_Depth, TAG_END );
  148.         tags[4] = RTSC_Flags;
  149.         if( bPrefs->bp_Flags & BS_ASKDEP ) {
  150.             tags[5] = SCREQF_DEPTHGAD|SCREQF_NONSTDMODES;
  151.             if( rtScreenModeRequestA( smRequest, "Screen Mode", BTAGS )) {
  152.                 bPrefs->bp_Depth = smRequest->DisplayDepth;
  153.                 bPrefs->bp_Mode = smRequest->DisplayID;
  154.             }
  155.         } else {
  156.             tags[5] = SCREQF_NONSTDMODES;
  157.             if( rtScreenModeRequestA( smRequest, "Screen Mode", BTAGS ))
  158.                 bPrefs->bp_Mode = smRequest->DisplayID;
  159.         }
  160.         tags[4] = TAG_END;
  161.         rtFreeRequest( smRequest );
  162.         setPrefs( bPrefs, GD_MDISPLAY );
  163.     } else EZRQ( "Not enough memory to allocate\nscreen mode requester." );
  164.     return( OK );
  165. }
  166.  
  167. int BMODClicked( void )
  168. {
  169.     sendModMsg( BM_DOPREFS, modulePort );
  170.  
  171.     return( OK );
  172. }
  173.  
  174. int LMODClicked( void )
  175. {
  176.     struct rtFileRequester *fRequest;
  177.  
  178.     if( fRequest = rtAllocRequest( RT_FILEREQ, 0L )) {
  179.         rtChangeReqAttr( fRequest, RTFI_Dir, bPrefs->bp_Dir, TAG_END );
  180.         tags[4] = RTFI_Flags;
  181.         tags[5] = FREQF_PATGAD;
  182.         if( rtFileRequestA( fRequest, bPrefs->bp_Name, "Please choose blanker module...", BTAGS )) {
  183.             CopyMem( fRequest->Dir, bPrefs->bp_Dir, 108 );
  184.             loadModule( 2 );
  185.         }
  186.         tags[4] = TAG_END;
  187.         rtFreeRequest( fRequest );
  188.     } else EZRQ( "Couldn't allocate file requester." );
  189.     return( OK );
  190. }
  191.  
  192. int BlankerOpen( void )
  193. {
  194.     struct rtFileRequester *fRequest;
  195.  
  196.     if( fRequest = rtAllocRequest( RT_FILEREQ, 0L )) {
  197.         rtChangeReqAttr( fRequest, RTFI_Dir, prefDir, RTFI_MatchPat, "#?.pre", TAG_END );
  198.         tags[4] = RTFI_Flags;
  199.         tags[5] = FREQF_PATGAD;
  200.         if( rtFileRequestA( fRequest, prefName, "Please choose prefs file...", BTAGS ))
  201.             if( rc = loadBlankerPrefs( prefName, fRequest->Dir, bPrefs )) prefError( rc );
  202.         tags[4] = TAG_END;
  203.         rtFreeRequest( fRequest );
  204.     } else EZRQ( "Couldn't allocate file requester." );
  205.     return( OK );
  206. }
  207.  
  208. int BlankerSaveAs( void )
  209. {
  210.     struct rtFileRequester *fRequest;
  211.  
  212.     if( fRequest = rtAllocRequest( RT_FILEREQ, 0L )) {
  213.         rtChangeReqAttr( fRequest, RTFI_Dir, prefDir, RTFI_MatchPat, "#?.pre", TAG_END );
  214.         tags[4] = RTFI_Flags;
  215.         tags[5] = FREQF_PATGAD;
  216.         if( rtFileRequestA( fRequest, prefName, "Please choose a save file...", BTAGS ))
  217.             saveBlankerPrefs( prefName, fRequest->Dir, bPrefs );
  218.         tags[4] = TAG_END;
  219.         rtFreeRequest( fRequest );
  220.     } else EZRQ( "Couldn't allocate file requester." );
  221.     return( OK );
  222. }
  223.  
  224. int BlankerAbout( void )
  225. {
  226.     EZRQ( VERS"\nby Michael D. Bayne\n\nbaynemd@nextwork.rose-hulman.edu" );
  227.     return( OK );
  228. }
  229.  
  230. int BlankerLoadMod( void )
  231. {
  232.     return( LMODClicked() );
  233. }
  234.  
  235. int BlankerQuit( void )
  236. {
  237.     return( QUIT );
  238. }
  239.  
  240. int BlankerLSaved( void )
  241. {
  242.     if( rc = loadPrefsFromENVARC( bPrefs )) prefError( rc );
  243.     return( OK );
  244. }
  245.  
  246. int BlankerRandPrefs( void )
  247. {
  248.     bPrefs->bp_Flags ^= BS_RANDOM;
  249.     return( OK );
  250. }
  251.  
  252. int BlankerCloseWindow( void )
  253. {
  254.     return( CLOSEWIN );
  255. }
  256.  
  257. int BlankerVanillaKey( void )
  258. {
  259.     switch( BlankerMsg.Code ) {
  260.     case 'c':
  261.         return( SMODEClicked() );
  262.     case 'r':
  263.         return( BMODClicked() );
  264.     case 'l':
  265.         return( BlankerLoadMod());
  266.     case 't':
  267.         ActivateGadget( BlankerGadgets[GD_TOUT], BlankerWnd, 0l );
  268.         return( OK );
  269.     case 'b':
  270.         ActivateGadget( BlankerGadgets[GD_BKEY], BlankerWnd, 0l );
  271.         return( OK );
  272.     case 'p':
  273.         ActivateGadget( BlankerGadgets[GD_PKEY], BlankerWnd, 0l );
  274.         return( OK );
  275.     case 'h':
  276.         return( HIDEClicked() );
  277.     case 's':
  278.         return( SAVEClicked() );
  279.     case 'q':
  280.         return( QUIT );
  281.     default:
  282.         return( OK );
  283.     }
  284. }
  285.